package com.lm.service.impl;

import com.lm.mapper.ServicePackageMapper;
import com.lm.pojo.ServicePackage;
import com.lm.pojo.Tag;
import com.lm.service.ServicePackageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author 15833
 * @version 1.0
 * @description: TODO 服务包实现层
 * @date 2025/9/21 22:26
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class ServicePackageServiceImpl implements ServicePackageService {

    //注入ServicePackageMapper接口
    @Autowired
    private ServicePackageMapper servicePackageMapper;

    @Override
    public List<ServicePackage> findServicePackageList(ServicePackage servicePackage) {
        return servicePackageMapper.findServicePackageList(servicePackage);
    }

    @Override
    public void addServicePackage(ServicePackage servicePackage) {
        servicePackageMapper.insert(servicePackage);
        servicePackage.getServiceItems().forEach(serviceItem -> {
            servicePackageMapper.addServicePackageItemRel(servicePackage.getServicePackageId(), serviceItem.getServiceItemId());
        });
    }

    @Override
    public void updateServicePackage(ServicePackage servicePackage) {
            servicePackageMapper.updateById(servicePackage);
    }
    
    @Override
    public ServicePackage findServicePackageDetail(Integer servicePackageId) {
        return servicePackageMapper.findServicePackageDetail(servicePackageId);
    }
    
    @Override
    public void deleteServicePackageItemRel(Integer servicePackageId, Integer serviceItemId) {
        servicePackageMapper.deleteServicePackageItemRel(servicePackageId, serviceItemId);
    }

    @Override
    public void addServicePackageItemRel(Integer servicePackageId, Integer serviceItemId) {
        servicePackageMapper.addServicePackageItemRel(servicePackageId, serviceItemId);
    }

    @Override
    public void addServicePackageTagRel(Integer servicePackageId, Integer tagId) {
        servicePackageMapper.addServicePackageTagRel(servicePackageId, tagId);
    }
    @Override
    public List<Tag> findTagsByServicePackageId(Integer servicePackageId) {
        return servicePackageMapper.findTagsByServicePackageId(servicePackageId);
    }

     @Override
    public void deleteServicePackageTagRel(Integer servicePackageId, Integer tagId) {
        servicePackageMapper.deleteServicePackageTagRel(servicePackageId, tagId);
    }
}
